<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  
  <link rel="shortcut icon" href="../img/favicon.ico">
  <title>活动工作者 - Workflow Core 中文文档</title>
  <link rel="stylesheet" href="static/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700" />

  <link rel="stylesheet" href="../css/theme.css" />
  <link rel="stylesheet" href="../css/theme_extra.css" />
  <link rel="stylesheet" href="static/github.min.css" />
  
  <script>
    // Current page data
    var mkdocs_page_name = "\u6d3b\u52a8\u5de5\u4f5c\u8005";
    var mkdocs_page_input_path = "activity-workers.md";
    var mkdocs_page_url = null;
  </script>
  
  <script src="../js/jquery-2.1.1.min.js" defer></script>
  <script src="../js/modernizr-2.8.3.min.js" defer></script>
  <script src="static/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
    <div class="wy-side-scroll">
      <div class="wy-side-nav-search">
        <a href=".." class="icon icon-home"> Workflow Core 中文文档</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="..">简介</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../getting-started/">入门指南</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../external-events/">外部事件</a>
                    </li>
                </ul>
                <ul class="current">
                    <li class="toctree-l1 current"><a class="reference internal current" href="./">活动工作者</a>
    <ul class="current">
    <li class="toctree-l2"><a class="reference internal" href="#json-yaml-api">JSON / YAML API</a>
    </li>
    </ul>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../error-handling/">错误处理</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../control-structures/">控制结构</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../saga-transactions/">saga事务</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../json-yaml-definitions/">JSON/YAML定义</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../persistence/">持久化</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../middleware/">中间件</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../multi-node-clusters/">多节点集群</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../ASPNETCore/">ASP.NET Core</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../Elasticsearch/">Elasticsearch插件</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../test-helpers/">测试助手</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../Extensions/">扩展</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../Samples/">示例</a>
                    </li>
                </ul>
      </div>
    </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="..">Workflow Core 中文文档</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="..">Docs</a> &raquo;</li>
    
      
    
    <li>活动工作者</li>
    <li class="wy-breadcrumbs-aside">
      
    </li>
  </ul>
  
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <h1 id="activities">活动(Activities)</h1>
<p>活动被定义为工作流可以等待的外部工作队列上的项。  </p>
<p>在这个例子中，工作流将在继续之前等待<code>activity-1</code>。 它还传递<code>data.Value1</code>的值到活动，然后将活动的结果映射到<code>data.Value2</code>。  </p>
<p>然后我们创建一个worker来处理活动项的队列。 它使用<code>GetPendingActivity</code>方法来获取一个活动和工作流正在等待的数据。  </p>
<pre><code class="language-csharp">public class ActivityWorkflow : IWorkflow&lt;MyData&gt;
{
    public void Build(IWorkflowBuilder&lt;MyData&gt; builder)
    {
        builder                
            .StartWith&lt;HelloWorld&gt;()
            .Activity(&quot;activity-1&quot;, (data) =&gt; data.Value1)
                .Output(data =&gt; data.Value2, step =&gt; step.Result)
            .Then&lt;PrintMessage&gt;()
                .Input(step =&gt; step.Message, data =&gt; data.Value2);
    }

}
...

var activity = host.GetPendingActivity(&quot;activity-1&quot;, &quot;worker1&quot;, TimeSpan.FromMinutes(1)).Result;

if (activity != null)
{
    Console.WriteLine(activity.Parameters);
    host.SubmitActivitySuccess(activity.Token, &quot;Some response data&quot;);
}
</code></pre>
<p>这一步的JSON表示如下所示  </p>
<pre><code class="language-json">{
    &quot;Id&quot;: &quot;activity-step&quot;,
    &quot;StepType&quot;: &quot;WorkflowCore.Primitives.Activity, WorkflowCore&quot;,
    &quot;Inputs&quot;: 
    {
        &quot;ActivityName&quot;: &quot;\&quot;activity-1\&quot;&quot;,
        &quot;Parameters&quot;: &quot;data.Value1&quot; 
    },
    &quot;Outputs&quot;: { &quot;Value2&quot;: &quot;step.Result&quot; }
}
</code></pre>
<h2 id="json-yaml-api">JSON / YAML API</h2>
<p><code>Activity</code>步骤可以使用如下输入进行配置  </p>
<table>
<thead>
<tr>
<th>字段</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>CancelCondition</td>
<td>指定取消条件的可选表达式</td>
</tr>
<tr>
<td>Inputs.ActivityName</td>
<td>指定活动名称的表达式</td>
</tr>
<tr>
<td>Inputs.Parameters</td>
<td>指定传递给活动工作者的参数的表达式</td>
</tr>
<tr>
<td>Inputs.EffectiveDate</td>
<td>指定有效日期的可选表达式</td>
</tr>
</tbody>
</table>
<pre><code class="language-json">{
    &quot;Id&quot;: &quot;MyActivityStep&quot;,
    &quot;StepType&quot;: &quot;WorkflowCore.Primitives.Activity, WorkflowCore&quot;,
    &quot;NextStepId&quot;: &quot;...&quot;,
    &quot;CancelCondition&quot;: &quot;...&quot;,
    &quot;Inputs&quot;: {
        &quot;ActivityName&quot;: &quot;\&quot;my-activity\&quot;&quot;,
        &quot;Parameters&quot;: &quot;data.SomeValue&quot;
    }
}
</code></pre>
<pre><code class="language-yaml">Id: MyActivityStep
StepType: WorkflowCore.Primitives.Activity, WorkflowCore
NextStepId: &quot;...&quot;
CancelCondition: &quot;...&quot;
Inputs:
  ActivityName: '&quot;my-activity&quot;'
  EventKey: '&quot;Key1&quot;'
  Parameters: data.SomeValue
</code></pre>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../error-handling/" class="btn btn-neutral float-right" title="错误处理">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../external-events/" class="btn btn-neutral" title="外部事件"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" aria-label="versions">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
      
        <span><a href="../external-events/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../error-handling/" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script>var base_url = '..';</script>
    <script src="../js/theme.js" defer></script>
      <script src="../search/main.js" defer></script>
    <script defer>
        window.onload = function () {
            SphinxRtdTheme.Navigation.enable(true);
        };
    </script>

</body>
</html>
